Home:ALL Converter>How Android UIAutomator 2 takeScreenshot on the App without WRITE_EXTERNAL_STORAGE permission?

How Android UIAutomator 2 takeScreenshot on the App without WRITE_EXTERNAL_STORAGE permission?

Ask Time:2018-11-22T20:47:34         Author:ChinKang

Json Formatter

Say we have an app named NoseBook, this app doesn't has the permission of android.permission.WRITE_EXTERNAL_STORAGE and we don't intent to request user for this permission.

uiautomator2 is the selected blackbox test framework, and we're trying to capture a screenshot during the test and save it somewhere, which later can be pulled from AVD and saved as report.

The API called is UiDevice#takescreenshot but the following error was shown

E/UiDevice: failed to save screen shot to file
java.io.FileNotFoundException: /storage/emulated/0/test.png (Permission denied)

The error will go away if we add the WRITE_EXTERNAL_STORAGE to the app NoseBook but it is not appropriate as this is only for our testing purpose, the actual app doesn't need that permission.

Note: screencap is the workaround i've noticed but I'm looking solution around uiautomator itself.

Environment: emulator API 25

Author:ChinKang,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53431391/how-android-uiautomator-2-takescreenshot-on-the-app-without-write-external-stora
yy